package com.azkj.album.utils

import android.content.Context
import android.view.View
import android.widget.ImageView
import android.widget.ProgressBar
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.bumptech.glide.request.target.Target
import com.lxj.xpopup.core.ImageViewerPopupView
import com.lxj.xpopup.interfaces.XPopupImageLoader
import com.lxj.xpopup.photoview.PhotoView
import java.io.File

class ImageLoader(var clickLongListener:(url: Any)-> Unit? = {}):XPopupImageLoader {

    override fun loadImage(position: Int, uri: Any, imageView: ImageView) {
        imageView.setOnLongClickListener {
            clickLongListener.invoke(uri)
            return@setOnLongClickListener true
        }
        //必须指定Target.SIZE_ORIGINAL，否则无法拿到原图，就无法享用天衣无缝的动画
        Glide.with(imageView).load(uri).apply(
            RequestOptions().override(
                Target.SIZE_ORIGINAL)).into(imageView)
    }

    override fun getImageFile(context: Context, uri: Any): File? {
        try {
            return Glide.with(context).downloadOnly().load(uri).submit().get()
        } catch (e: Exception) {
            e.printStackTrace()
        }
        return null
    }

}